import React, { Component } from 'react'
import { StyleSheet, Text, Image, TouchableOpacity, View, Dimensions, RefreshControl } from 'react-native';
import { connect } from 'react-redux'
import { Header } from 'react-navigation';
import HeaderImageScrollView, { TriggeringView } from 'react-native-image-header-scroll-view';

import { createAction, NavigationActions } from '../utils'

const MIN_HEIGHT = Header.HEIGHT;
const MAX_HEIGHT = 200;

const styles = StyleSheet.create({
  container: {
    flex: 1
  },
  image: {
    height: MAX_HEIGHT,
    width: Dimensions.get('window').width
  },
  button: {
    borderWidth: 1,
    borderRadius: 8,
    paddingVertical: 10,
    paddingHorizontal: 30,
    borderColor: 'white',
    backgroundColor: '#00000066'
  },
  buttonText: {
    color: 'white',
    backgroundColor: 'transparent'
  }
});

@connect(({ app }) => ({ ...app }))
class Account extends Component {
  constructor() {
    super();
    this.state = {
      refreshing: false
    };
  }

  _onRefresh() {
    this.setState({
      refreshing: true
    });

    setTimeout(() => {
      this.setState({
        refreshing: false
      });
    }, 2000);
  }

  gotoLogin = () => {
    this.props.dispatch(NavigationActions.navigate({ routeName: 'Login' }))
  }

  logout = () => {
    this.props.dispatch(createAction('app/logout')())
  }

  render() {
    return (
      <View style={styles.container}>
        <HeaderImageScrollView
          maxHeight={MAX_HEIGHT}
          minHeight={MIN_HEIGHT}
          minOverlayOpacity={0.4}
          renderHeader={() => <Image source={{ uri: 'http://seopic.699pic.com/photo/50063/5074.jpg_wh1200.jpg'}} style={styles.image} />}
          refreshControl={
            <RefreshControl
              refreshing={this.state.refreshing}
              onRefresh={this._onRefresh.bind(this)}
              tintColor="white"
            />
          }
          scrollViewBackgroundColor="#ddddff"
        >
          <View style={{ height: 1000 }} />
        </HeaderImageScrollView>
      </View>
    )
  }
}


export default Account
